package day2;

import java.util.Scanner;

public class 最小花费爬楼梯 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		// 注意 hasNext 和 hasNextLine 的区别
		while (in.hasNextInt()) { // 注意 while 处理多个 case
			int n = in.nextInt();
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = in.nextInt();
			}
			if (n == 1) {
				System.out.println(arr[0]);
			} else {
				int[] dp = new int[n + 1];
				dp[0] = dp[1] = 0;
				for (int i = 2; i <= n; i++) {
					dp[i] = Math.min(dp[i - 1] + arr[i - 1], dp[i - 2] + arr[i - 2]);
				}
				System.out.println(dp[n]);
			}
		}
	}
}
